<template>
  <div class="app-container">
      <el-table border :data="tableData" style="width: 100%" header-align="center">
          <el-table-column prop="title" label="意见标题"></el-table-column>
          <el-table-column prop="content" label="意见内容"></el-table-column>
          <el-table-column prop="liuyanshijian" label="留言时间" width="100px"></el-table-column>
          <el-table-column prop="ask.shifouyinsi" label="是否显示" width="100px">
              <template slot-scope="scope">
                  <span v-if="scope.row.isVisible === '1'">是</span>
                  <span v-if="scope.row.isVisible === '0'">否</span>
              </template>
          </el-table-column>
          <el-table-column label="操作" width="100px">
              <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="reply(scope.row)">修改</el-button>
              </template>    
          </el-table-column>
      </el-table>
      <el-pagination style="margin-top:20px"
          background
          @size-change="handleChangeSize"
          @current-change="handleSizeChange"
          :current-page="1"
          :page-sizes="[16, 40, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          >
      </el-pagination> 
  </div>    
</template> 
<style>
.avatar-uploader .el-upload {
border: 1px dashed #d9d9d9;
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
}
.avatar-uploader .el-upload:hover {
border-color: #409eff;
}
.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
line-height: 178px;
text-align: center;
}
.avatar {
width: 178px;
height: 178px;
display: block;
}
</style>
<script>
import { getToken } from "@/utils/auth"; 
import { getAlljianyi, editNote } from "@/api/yxzx/email";
export default {
  data() {
      return {
          loading: true,
          tableData: [],
          pageindex: 1,
          pagesize: 10,
          total: 0,
          dialogVisible:false,
          form: {},
          askid: '',
          dialogxiangqingVisible:false,
          tableDatareply: [],
      }
  },
  created() {
      this.getNoedata()
  }, 
  methods: {
      // 查询所有留言
      getNoedata(){
        getAlljianyi(this.pageindex,this.pagesize).then((res) => {
            this.tableData = res.rows
            this.total = res.total
        });
      },
      handleSizeChange(val) {
          this.pageindex = val;
          this.getNoedata()
      },
      handleChangeSize(val){
          this.pagesize = val;
          this.getNoedata()
      },
      reply(val){
        this.$confirm('是否显示这条意见?', '提示', {
          confirmButtonText: '是',
          cancelButtonText: '否',
          type: 'warning'
        }).then(() => {
            editNote(val.adviceId, '1').then((res) => {
                this.$message({
                    type: 'success',
                    message: '已成功显示该意见!'
                });
                this.getNoedata()
            }); 
          
        }).catch(() => {
            editNote(val.adviceId, '0').then((res) => {
                this.$message({
                    type: 'info',
                    message: '已取消显示这条意见'
                });
                this.getNoedata()
            });
                    
        });
      },
      lookDetail(val){
          this.tableDatareply = val
          this.dialogxiangqingVisible = true
      },
      onSubmit(){
          if(!this.form.content || this.form.content==''){
              this.$message.error('请填写回复内容！');
              return
          }
          replyNote(this.askid,this.form.content).then((res) => {
              console.log(res)
              if(res.result == '1'){
                  this.$message({
                      message: res.resultContent,
                      type: 'success'
                  });
                  this.getNoedata()
                  this.form.content = ''
                  this.dialogVisible = false
              }
          });
      },
      cancle(){
          this.form.content = ''
          this.dialogVisible = false
      },
      closeDialog(){
          this.form.content = ''
      }
  } 
} 
</script> 